package com.aaa.service.sds.impl;

import com.aaa.dao.sds.ViewTestResultSdsDao;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.sas.TestResultSas;
import com.aaa.entity.sds.TestResultSds;
import com.aaa.entity.sds.ViewTestResultSds;
import com.aaa.service.sds.ViewTestResultSdsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (ViewTestResultMht)表服务实现类
 *
 * @author makejava
 * @since 2022-09-05 19:41:05
 */
@Service
public class ViewTestResultSdsServiceImpl implements ViewTestResultSdsService {
    @Resource
    private ViewTestResultSdsDao viewTestResultSdsDao;

    //查询所有
    @Override
    public Page queryAll(PageSortEntity page, ViewTestResultSds viewTestResultSds) {
        PageHelper.startPage(page.getPage(), page.getLimit(), page.getOrderString());
        List<ViewTestResultSds> list = viewTestResultSdsDao.queryAll(viewTestResultSds);
        Page page1 = (Page) list;
        return page1;
    }

    //删除
    @Override
    public boolean delete(String id) {
        boolean delete = viewTestResultSdsDao.delete(id);
        return delete;
    }

    //查询ID
    @Override
    public ViewTestResultSds queryResultById(Integer id) {
        ViewTestResultSds vs = viewTestResultSdsDao.queryResultById(id);
        return vs;
    }

    //查询所有结果
    @Override
    public Map<String, Integer> queryAllPlanSds() {
        int normal = 0;
        int mild = 0;
        int moderate = 0;
        int severe = 0;
        List<ViewTestResultSds> viewSds = this.viewTestResultSdsDao.queryAllPlanSds();
        for (ViewTestResultSds ppp : viewSds) {
            if (ppp.getSum() <= 50) {
                normal++;
            } else if (ppp.getSum() >= 50 && ppp.getSum() <= 59) {
                mild++;
            } else if (ppp.getSum() >= 60 && ppp.getSum() <= 69) {
                moderate++;
            } else {
                severe++;
            }
        }
        Map<String, Integer> map = new HashMap<>();
        map.put("normal", normal);
        map.put("mild", mild);
        map.put("moderate", moderate);
        map.put("severe", severe);
        return map;
    }

    /*答题结束根据分数跳转测试结果界面*/
    @Override
    public String selectById(Integer Id) {
        ViewTestResultSds viewTestResultSds = viewTestResultSdsDao.selectById(Id);
        Integer sum = viewTestResultSds.getSum();
        if (sum <= 53) {
            return "sdsResult/SdsNormal.jsp";
        } else if (sum < 62) {
            return "sdsResult/SdsMild.jsp";
        } else if (sum < 72) {
            return "sdsResult/SdsModerate.jsp";
        } else {
            return "sdsResult/SdsSevere.jsp";
        }
    }
    @Override
    public Page selectAllByPerson(PageSortEntity page, TestResultSds id) {
        PageHelper.startPage(page.getPage(), page.getLimit(), page.getOrderString());
        List<TestResultSds> viewPersonResultSds = viewTestResultSdsDao.selectAllByPerson(id);
        Page page1 = (Page) viewPersonResultSds;
        return page1;
    }

}
